import request from '@/utils/request';
import { TableQuery } from './types';

// 查询生成表数据
export const list = (query: TableQuery) => {
  return request({
    url: '/online/list',
    method: 'get',
    params: query
  });
};

// 查询online表详细信息
export const getOnlineForm = (tableId: string | number) => {
  return request({
    url: '/online/' + tableId,
    method: 'get'
  });
};

// 获取数据源名称
export const getDataNames = () => {
  return request({
    url: '/online/getDataNames',
    method: 'get'
  });
};

// 查询online表列表数据
export const listOnlineData = (tableId: string | number, tableName: string, query: PageQuery ) => {
  return request({
    url: '/online/getData/'+ tableId + '/' + tableName,
    method: 'get',
    params: query
  });
};

// 查询online字典表列表数据
export const listTableData = (tableName: string, query: PageQuery ) => {
  return request({
    url: '/online/getTableData/'+ tableName,
    method: 'get',
    params: query
  });
};

// 新增或更新online表单数据
export const addOrUpdateOnlineData = (tableId: string | number, tableName: string, data: any ) => {
  return request({
    url: '/online/addOrUpdateData/'+ tableId + '/' + tableName,
    method: 'post',
    data: data
  });
};

// 新增或更新online表单数据
export const addOrUpdateOnlineDataByName = (tableName: string, data: any ) => {
  return request({
    url: '/online/addOrUpdateDataByName/'+ tableName,
    method: 'post',
    data: data
  });
};

// 删除online表单数据
export function delOnlineData(tableId: number, tableName: string, ids: (string | number)) {
  return request({
    url: `/online/delOnlineData/${tableId}/${tableName}`,
    method: 'delete',
    data: ids // 根据实际API要求可能需要调整为params或其他形式
  });
}

// 获取online表单详细数据
export function getOnlineData(tableId: number, tableName: string, id: (string | number)) {
  return request({
    url: `/online/getOnlineData/${tableId}/${tableName}`,
    method: 'post',
    data: id
  });
}

// 弹窗详情数据
export const getPopupDetail = (
  tableId: string | number,
  tableName: string,
  id: string | number
) => {
  return request.get(`/online/detail/${tableId}/${tableName}/${id}`)
}
